Use Entry::or_insert where possible
authorAlex Crichton <alex@alexcrichton.com>
Mon, 30 Mar 2015 20:39:16 +0000 (13:39 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 31 Mar 2015 00:54:20 +0000 (17:54 -0700)
Cargo.lock
src/cargo/core/registry.rs
src/cargo/core/resolver/mod.rs
src/cargo/lib.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/job_queue.rs
src/cargo/util/dependency_queue.rs
src/cargo/util/graph.rs
src/cargo/util/sha256.rs

index fe19cc4e7aa9c97e56bde21c23b3ddce9066d7b9..96f58ff9ed0e2a1759c629b0b4dc7463a09fea06 100644 (file)
@@ -4,9 +4,9 @@ version = "0.1.0"
 dependencies = [
  "advapi32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "curl 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "docopt 0.6.55 (registry+https://github.com/rust-lang/crates.io-index)",
+ "docopt 0.6.56 (registry+https://github.com/rust-lang/crates.io-index)",
  "env_logger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "flate2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "flate2 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "git2 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "git2-curl 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "glob 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -18,9 +18,9 @@ dependencies = [
  "registry 0.1.0",
  "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
  "semver 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
- "tar 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tar 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "tempdir 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "term 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "threadpool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
  "toml 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -46,7 +46,7 @@ name = "curl"
 version = "0.2.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "curl-sys 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "curl-sys 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl-sys 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "url 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -54,7 +54,7 @@ dependencies = [
 
 [[package]]
 name = "curl-sys"
-version = "0.1.17"
+version = "0.1.18"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -65,7 +65,7 @@ dependencies = [
 
 [[package]]
 name = "docopt"
-version = "0.6.55"
+version = "0.6.56"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -84,7 +84,7 @@ dependencies = [
 
 [[package]]
 name = "flate2"
-version = "0.2.3"
+version = "0.2.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -103,7 +103,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "libgit2-sys 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libgit2-sys 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "url 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -143,7 +143,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "libgit2-sys"
-version = "0.2.7"
+version = "0.2.8"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -257,7 +257,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "tar"
-version = "0.2.6"
+version = "0.2.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
@@ -270,7 +270,7 @@ dependencies = [
 
 [[package]]
 name = "term"
-version = "0.2.3"
+version = "0.2.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "kernel32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
index adf05b0fad622ee1cabedf66bc39c95ea417a289..86adfc55953f9bafe5f5b6ed524dc375d3566a86 100644 (file)
@@ -1,6 +1,5 @@
 use std::collections::HashSet;
 use std::collections::hash_map::HashMap;
-use std::collections::hash_map::Entry::{Occupied, Vacant};
 
 use core::{Source, SourceId, SourceMap, Summary, Dependency, PackageId, Package};
 use util::{CargoResult, ChainError, Config, human, profile};
@@ -148,14 +147,10 @@ impl<'a, 'b> PackageRegistry<'a, 'b> {
     }
 
     pub fn register_lock(&mut self, id: PackageId, deps: Vec<PackageId>) {
-        let sub_map = match self.locked.entry(id.source_id().clone()) {
-            Occupied(e) => e.into_mut(),
-            Vacant(e) => e.insert(HashMap::new()),
-        };
-        let sub_vec = match sub_map.entry(id.name().to_string()) {
-            Occupied(e) => e.into_mut(),
-            Vacant(e) => e.insert(Vec::new()),
-        };
+        let sub_map = self.locked.entry(id.source_id().clone())
+                                 .or_insert(HashMap::new());
+        let sub_vec = sub_map.entry(id.name().to_string())
+                             .or_insert(Vec::new());
         sub_vec.push((id, deps));
     }
 
index 39bd9a321859ef45cfa4d5e7edb5375912c56ff9..8c2f7b8f6d431129a59aa0490c3e0108b4c461d9 100644 (file)
@@ -1,7 +1,6 @@
 use std::cell::RefCell;
 use std::collections::HashSet;
 use std::collections::hash_map::HashMap;
-use std::collections::hash_map::Entry::{Occupied, Vacant};
 use std::fmt;
 use std::rc::Rc;
 use semver;
@@ -92,10 +91,7 @@ impl Resolve {
                     spec: &PackageIdSpec) {
             let mut version_cnt = HashMap::new();
             for id in ids.iter() {
-                match version_cnt.entry(id.version()) {
-                    Vacant(e) => { e.insert(1); }
-                    Occupied(e) => *e.into_mut() += 1,
-                }
+                *version_cnt.entry(id.version()).or_insert(0) += 1;
             }
             for id in ids.iter() {
                 if version_cnt[id.version()] == 1 {
@@ -483,10 +479,9 @@ fn resolve_features<'a>(cx: &mut Context, parent: &'a Summary,
     // Record what list of features is active for this package.
     if used_features.len() > 0 {
         let pkgid = parent.package_id();
-        match cx.resolve.features.entry(pkgid.clone()) {
-            Occupied(entry) => entry.into_mut(),
-            Vacant(entry) => entry.insert(HashSet::new()),
-        }.extend(used_features.into_iter());
+        cx.resolve.features.entry(pkgid.clone())
+          .or_insert(HashSet::new())
+          .extend(used_features);
     }
 
     Ok(ret)
@@ -551,10 +546,9 @@ fn build_features(s: &Summary, method: Method)
         match parts.next() {
             Some(feat) => {
                 let package = feat_or_package;
-                match deps.entry(package.to_string()) {
-                    Occupied(e) => e.into_mut(),
-                    Vacant(e) => e.insert(Vec::new()),
-                }.push(feat.to_string());
+                deps.entry(package.to_string())
+                    .or_insert(Vec::new())
+                    .push(feat.to_string());
             }
             None => {
                 let feat = feat_or_package;
@@ -572,10 +566,7 @@ fn build_features(s: &Summary, method: Method)
                         }
                     }
                     None => {
-                        match deps.entry(feat.to_string()) {
-                            Occupied(..) => {} // already activated
-                            Vacant(e) => { e.insert(Vec::new()); }
-                        }
+                        deps.entry(feat.to_string()).or_insert(Vec::new());
                     }
                 }
                 visited.remove(&feat.to_string());
index ac232f2fb77ae282fb2ad9409caf84ce6de81a37..8cf9d8ab4702b46d79da21b75d40af5237c7e714 100644 (file)
@@ -139,7 +139,7 @@ pub fn shell(verbose: bool) -> MultiShell {
     }
     #[cfg(windows)]
     fn isatty(fd: libc::c_int) -> bool {
-        extern crate kernel32_sys as kernel32;
+        extern crate kernel32;
         extern crate winapi;
         unsafe {
             let handle = kernel32::GetStdHandle(if fd == libc::STDOUT_FILENO {
index dca21525c53cd5c168b6298978b6c6864e92bded..5ac3c6779d2bd90df4094435dbb1db128905fefb 100644 (file)
@@ -1,4 +1,3 @@
-use std::collections::hash_map::Entry::{Occupied, Vacant};
 use std::fs::{self, File, OpenOptions};
 use std::io::prelude::*;
 use std::io::{BufReader, SeekFrom};
@@ -68,10 +67,8 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>,
                 cx.compilation.binaries.push(dst);
             } else if target.is_lib() {
                 let pkgid = pkg.package_id().clone();
-                match cx.compilation.libraries.entry(pkgid) {
-                    Occupied(entry) => entry.into_mut(),
-                    Vacant(entry) => entry.insert(Vec::new()),
-                }.push(dst);
+                cx.compilation.libraries.entry(pkgid).or_insert(Vec::new())
+                  .push(dst);
             }
         }
     }
index 103726755e4e7567456664ecc23fbf7ef9e6b321..087880b15390f417f329ae1999b1a8b9b7ae86af 100644 (file)
@@ -1,6 +1,5 @@
 use std::collections::HashSet;
 use std::collections::hash_map::HashMap;
-// use std::collections::hash_map::Entry::{Occupied, Vacant};
 use std::sync::mpsc::{channel, Sender, Receiver};
 
 use threadpool::ThreadPool;
index 8dfa6c708811ad50637786d3b4cd01e27bc0f2bd..6d5553a6e7a3bed9b62392979ed13836f53c38ee 100644 (file)
@@ -86,10 +86,7 @@ impl<K: Dependency, V> DependencyQueue<K, V> {
         let mut my_dependencies = HashSet::new();
         for dep in key.dependencies(cx).into_iter() {
             assert!(my_dependencies.insert(dep.clone()));
-            let rev = match self.reverse_dep_map.entry(dep) {
-                Occupied(entry) => entry.into_mut(),
-                Vacant(entry) => entry.insert(HashSet::new()),
-            };
+            let rev = self.reverse_dep_map.entry(dep).or_insert(HashSet::new());
             assert!(rev.insert(key.clone()));
         }
         &mut slot.insert((my_dependencies, value)).1
index 0639b63baa58603804f54cd7f180a2b5b81532de..ad02a04b152506873b0289ae9598c744dced0b26 100644 (file)
@@ -1,9 +1,7 @@
 use std::fmt;
 use std::hash::Hash;
-use std::collections::hash_set::HashSet;
+use std::collections::hash_set::{HashSet, Iter};
 use std::collections::hash_map::{HashMap, Keys};
-use std::collections::hash_map::Entry::{Occupied, Vacant};
-use std::collections::hash_set::Iter;
 
 pub struct Graph<N> {
     nodes: HashMap<N, HashSet<N>>
@@ -27,10 +25,7 @@ impl<N: Eq + Hash + Clone> Graph<N> {
     }
 
     pub fn link(&mut self, node: N, child: N) {
-        match self.nodes.entry(node) {
-            Occupied(entry) => entry.into_mut(),
-            Vacant(entry) => entry.insert(HashSet::new()),
-        }.insert(child);
+        self.nodes.entry(node).or_insert(HashSet::new()).insert(child);
     }
 
     pub fn get_nodes(&self) -> &HashMap<N, HashSet<N>> {
index 27a043012019a1e80b21e6af812c871fb100346b..8066ab74e2d96a3f641ce7d4c0792a7cf5db4647 100644 (file)
@@ -69,7 +69,7 @@ mod imp {
 #[cfg(windows)]
 mod imp {
     extern crate winapi;
-    extern crate advapi32_sys as advapi32;
+    extern crate advapi32;
     use std::io;
     use std::ptr;